package com.demo.java.OD301_350.OD301;

import java.util.Scanner;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【狼羊过河 or 羊、狼、农夫过河】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/146097237
 */
public class OdMain {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String inputStr = scanner.nextLine();
        String[] numsStr = inputStr.split(" ");
        int numSheep = Integer.parseInt(numsStr[0]);
        int numWolf = Integer.parseInt(numsStr[1]);
        int boatCapacity = Integer.parseInt(numsStr[2]);

        // 如果羊的数量小于等于狼的数量，直接返回0
        if (numSheep <= numWolf) {
            System.out.println(0);
            return;
        }

        // 如果船的容量小于狼的数量，则优先运输狼
        if (numWolf < boatCapacity) {
            if (numWolf < Math.floor(boatCapacity / 2.0)) {
                numSheep -= boatCapacity - numWolf;
            }
            System.out.println((int) Math.ceil(numSheep / (double) boatCapacity) + 1);
            return;
        }

        // 初始化羊和狼的数量
        numWolf -= boatCapacity - 1; // 先运输狼
        int numWolfOpposite = boatCapacity - 1;
        numSheep -= boatCapacity; // 再运输羊
        int numSheepOpposite = boatCapacity;
        int result = 2; // 起初需要两次运输

        // 计算每次船上可载的羊和狼数量
        int sheepBoat = (int) Math.ceil(boatCapacity / 2.0) + (boatCapacity % 2 == 0 ? 1 : 0);
        int wolfBoat = boatCapacity - sheepBoat;

        // 模拟每次运输
        while (numSheep > 0) {
            if (numSheep - sheepBoat > numWolf - wolfBoat || (numSheep == sheepBoat && numWolf == wolfBoat)) {
                numSheep -= sheepBoat;
                numSheepOpposite += sheepBoat;
                numWolf -= wolfBoat;
                numWolfOpposite += wolfBoat;
                result += 1;
            } else {
                int tmp = numSheepOpposite - numWolfOpposite - 1;
                if (tmp == 0) {
                    System.out.println(0);
                    return;
                }
                numWolf -= tmp;
                numWolfOpposite += tmp;
                result += 1;
            }
        }

        System.out.println(result);
    }
}